home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 4 code / Poly. in Code Resources / Virtual WDEF / WindowFrame.cp < prev    next >
Encoding:
Text File  |  1990-07-28  |  2.6 KB  |  106 lines  |  [TEXT/MPS ]

  1. /*
  2.     WindowFrame.cp
  3.     
  4.     Implementation of WindowFrame class.
  5.     
  6.     by Patrick Beard.
  7.     
  8.     ©1990 by Patrick C. Beard.  All rights reserved.
  9.  */
  10.  
  11. #ifndef __WINDOWFRAME__
  12. #include "WindowFrame.h"
  13. #endif
  14.  
  15. #include <Events.h>
  16. #include <Script.h>
  17.  
  18. static unsigned short GrowIconBits[] = {
  19.     0x0001, 0x0001, 0x0005, 0x0005,
  20.     0x0015, 0x0015, 0x0015, 0x0015,
  21.     0x0015, 0x0015, 0x0015, 0x0FF5,
  22.     0x0005, 0x3FFD, 0x0001, 0xFFFF,
  23.     0x0001, 0x0001, 0x0005, 0x0005,
  24.     0x0015, 0x0015, 0x0015, 0x0015,
  25.     0x0015, 0x0015, 0x0015, 0x0FF5,
  26.     0x0005, 0x3FFD, 0x0001, 0xFFFF
  27. };
  28.  
  29. void WindowFrame::New(WindowPeek theWindow)
  30. {
  31.     WindowDefinition::New(theWindow);
  32.  
  33.     Lock();
  34.     itsBorderRgn = NewRgn();
  35.     Unlock();
  36. }
  37.  
  38. void WindowFrame::Dispose()
  39. {
  40.     DisposeRgn(itsBorderRgn);
  41. }
  42.  
  43. void WindowFrame::CalcRgns()
  44. {
  45.     GrafPtr oldPort; GetPort(&oldPort);
  46.     SetPort((GrafPtr)itsWindow);
  47.     Rect portRect = itsWindow->port.portRect;
  48.     LocalToGlobal(&topLeft(portRect));
  49.     LocalToGlobal(&botRight(portRect));
  50.     SetPort(oldPort);    
  51.     RectRgn(itsWindow->contRgn, &portRect);
  52.     RectRgn(itsWindow->strucRgn, &portRect);
  53.     short insetAmount = -(5 + GetWVariant((WindowPtr)itsWindow));
  54.     InsetRgn(itsWindow->strucRgn, insetAmount, insetAmount);
  55. }
  56.  
  57. void WindowFrame::DrawFrame()
  58. {
  59.     if(!itsWindow->visible)
  60.         return;
  61.     
  62.     // draw everything.
  63.     FrameRgn(itsWindow->strucRgn);
  64.     DiffRgn(itsWindow->strucRgn, itsWindow->contRgn, itsBorderRgn);
  65.     FillRgn(itsBorderRgn, (itsWindow->hilited ? qd.black : qd.ltGray));
  66.     if(itsWindow->hilited) {
  67.         BitMap growIcon = { (Ptr)GrowIconBits, 2, {0, 0, 16, 16} };
  68.         Rect growArea = (**itsWindow->strucRgn).rgnBBox;
  69.         growArea.left = growArea.right - 16;
  70.         growArea.top = growArea.bottom - 16;
  71.         GrafPtr curPort; GetPort(&curPort);
  72.         CopyBits(&growIcon, &curPort->portBits, &growIcon.bounds, &growArea, srcCopy, itsBorderRgn);
  73.     }
  74.     Rect frame = (**itsWindow->contRgn).rgnBBox;
  75.     InsetRect(&frame, -1, -1);
  76.     FrameRect(&frame);
  77.     frame = (**itsWindow->strucRgn).rgnBBox;
  78.     FrameRect(&frame);
  79. }
  80.  
  81. void WindowFrame::DrawGrowImage(Rect& growRect)
  82. {
  83.     Rect strucRect = growRect;
  84.     short insetAmount = -(5 + GetWVariant((WindowPtr)itsWindow));
  85.     InsetRect(&strucRect, insetAmount, insetAmount);
  86.     FrameRect(&growRect);
  87.     FrameRect(&strucRect);
  88. }
  89.  
  90. long WindowFrame::Hit(Point& whereHit)
  91. {
  92.     if(PtInRgn(whereHit, itsWindow->contRgn))
  93.         return wInContent;
  94.     DiffRgn(itsWindow->strucRgn, itsWindow->contRgn, itsBorderRgn);
  95.     if(PtInRgn(whereHit, itsBorderRgn)) {
  96.         Rect growArea = (**itsWindow->strucRgn).rgnBBox;
  97.         growArea.left = growArea.right - 16;
  98.         growArea.top = growArea.bottom - 16;
  99.         if(PtInRect(whereHit, &growArea))
  100.             return wInGrow;
  101.  
  102.         return wInDrag;
  103.     }
  104.     return wNoHit;
  105. }
  106.